// sm3_demo.c
#include <stdio.h>
#include <string.h>
#include <gmssl/sm3.h>

void print_hex(const char* label, const uint8_t *data, size_t len) {
    printf("%s: ", label);
    for (size_t i = 0; i < len; i++) {
        printf("%02x", data[i]);
    }
    printf("\n");
}

int main(void) {
    const char *msg = "Hello, SM3!";
    size_t msg_len = strlen(msg);

    // 1. SM3 摘要计算
    uint8_t dgst[SM3_DIGEST_SIZE]; // 32 bytes
    SM3_CTX ctx;
    sm3_init(&ctx);
    sm3_update(&ctx, (const uint8_t *)msg, msg_len);
    sm3_finish(&ctx, dgst);

    print_hex("SM3 digest", dgst, SM3_DIGEST_SIZE);

    return 0;
}
